unit StatsSrc;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FIBDatabase, pFIBDatabase, cxStyles, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinCaramel, dxSkinCoffee, dxSkinDarkSide,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin,
  dxSkinSilver, dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  FIBDataSet, pFIBDataSet, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    db: TpFIBDatabase;
    vStats: TcxGridDBTableView;
    gStatsLevel1: TcxGridLevel;
    gStats: TcxGrid;
    qStats: TpFIBDataSet;
    ds: TDataSource;
    tr: TpFIBTransaction;
    qStatsPID: TFIBIntegerField;
    qStatsPHONE: TFIBStringField;
    qStatsWRONG_NUMBER: TFIBIntegerField;
    qStatsERROR_COUNT: TFIBIntegerField;
    qStatsWASTED_COUNT: TFIBIntegerField;
    qStatsMISSED_COUNT: TFIBIntegerField;
    qStatsDELIVERED_COUNT: TFIBIntegerField;
    qStatsEXPIRED_COUNT: TFIBIntegerField;
    qStatsUNDELIVERED_COUNT: TFIBIntegerField;
    qStatsACCEPTED_COUNT: TFIBIntegerField;
    qStatsREJECTED_COUNT: TFIBIntegerField;
    qStatsDELETED_COUNT: TFIBIntegerField;
    qStatsUNKNOWN_COUNT: TFIBIntegerField;
    qStatsSTATUS_LIST: TFIBStringField;
    vStatsPID: TcxGridDBColumn;
    vStatsPHONE: TcxGridDBColumn;
    vStatsWRONG_NUMBER: TcxGridDBColumn;
    vStatsERROR_COUNT: TcxGridDBColumn;
    vStatsWASTED_COUNT: TcxGridDBColumn;
    vStatsMISSED_COUNT: TcxGridDBColumn;
    vStatsDELIVERED_COUNT: TcxGridDBColumn;
    vStatsEXPIRED_COUNT: TcxGridDBColumn;
    vStatsUNDELIVERED_COUNT: TcxGridDBColumn;
    vStatsACCEPTED_COUNT: TcxGridDBColumn;
    vStatsREJECTED_COUNT: TcxGridDBColumn;
    vStatsDELETED_COUNT: TcxGridDBColumn;
    vStatsUNKNOWN_COUNT: TcxGridDBColumn;
    vStatsSTATUS_LIST: TcxGridDBColumn;
    qStatsFULL_WASTED_COUNT: TFIBIntegerField;
    qStatsFULL_DELIVERED_COUNT: TFIBIntegerField;
    vStatsFULL_WASTED_COUNT: TcxGridDBColumn;
    vStatsFULL_DELIVERED_COUNT: TcxGridDBColumn;
    qStatsSORT_ORDER: TFIBSmallIntField;
    vStatsAVAILABLE: TcxGridDBColumn;
    vStatsSORT_ORDER: TcxGridDBColumn;
    qStatsAVAILABLE: TFIBBooleanField;
    pTop: TPanel;
    cShowList: TCheckBox;
    qStatsWD_RATIO: TFIBBCDField;
    vStatsWD_RATIO: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure vStatsCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure cShowListClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  try
    db.Open;
  except
  end;
  if not db.Connected then
    Application.Terminate
  else
    qStats.Open;
end;

procedure TForm1.vStatsCustomDrawCell(Sender: TcxCustomGridTableView;
  ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
  var ADone: Boolean);
begin
  if (vStats.DataController.Values[AViewInfo.GridRecord.RecordIndex,vStatsWRONG_NUMBER.Index] > 0) then
  begin
    ACanvas.Brush.Color := $B9DAFF;
    exit;
  end;
  if (vStats.DataController.Values[AViewInfo.GridRecord.RecordIndex,vStatsWASTED_COUNT.Index] > 0) then
    if (AViewInfo.Item.Index = vStatsWASTED_COUNT.Index) then
      ACanvas.Brush.Color := $7280FA
    else
      if (AViewInfo.Item.Index = vStatsFULL_WASTED_COUNT.Index) then
        ACanvas.Brush.Color := $7AA0FF;
  if (vStats.DataController.Values[AViewInfo.GridRecord.RecordIndex,vStatsDELIVERED_COUNT.Index] > 0) then
    if (AViewInfo.Item.Index = vStatsDELIVERED_COUNT.Index) then
      ACanvas.Brush.Color := $EEEEAF
    else
      if (AViewInfo.Item.Index = vStatsFULL_DELIVERED_COUNT.Index) then
        ACanvas.Brush.Color := $FFFFE0;
  if (vStats.DataController.Values[AViewInfo.GridRecord.RecordIndex,vStatsERROR_COUNT.Index] > 0) and
     (vStats.DataController.Values[AViewInfo.GridRecord.RecordIndex,vStatsDELIVERED_COUNT.Index] = 0) then
    ACanvas.Brush.Color := $AAE8EE
  else
    if (vStats.DataController.Values[AViewInfo.GridRecord.RecordIndex,vStatsMISSED_COUNT.Index] > 0) and
       (vStats.DataController.Values[AViewInfo.GridRecord.RecordIndex,vStatsDELIVERED_COUNT.Index] = 0) then
      ACanvas.Brush.Color := $D2FAFA;

  {if (vStats.DataController.FocusedRecordIndex >= 0) and Assigned(AViewInfo.Item) and ( > 0) and (vTheme.DataController.RecordCount > 0) then
  begin
    if vKids.Columns[AViewInfo.Item.Index].Position.Band.Tag = vTheme.DataController.Values[vTheme.DataController.FocusedRecordIndex,0] then
      ACanvas.Brush.Color := clMoneyGreen;
  end; }
end;

procedure TForm1.cShowListClick(Sender: TObject);
begin
  vStats.OptionsView.CellAutoHeight := not cShowList.Checked;
end;

end.
